package com.lbssoft.gpsbd.controller;

import com.lbssoft.gpsbd.annotation.LogAnnotation;
import com.lbssoft.gpsbd.model.Result;
import com.lbssoft.gpsbd.service.CacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

@Api("缓存处理")
@RestController
@RequestMapping(value="/cache")
public class CacheController {

	@Autowired
	CacheService cacheService;

	@ApiOperation(value="清理缓存", notes="清理缓存")
	@LogAnnotation(targetType = "cache",action = "delete",remark = "清理缓存")
	@ApiImplicitParam(paramType="path",name = "type", value = "缓存类型，token/permiss", dataType = "String")
	@RequiresPermissions("system:cache:delete")
	@RequestMapping(value = "/clean/{type}",method = {RequestMethod.DELETE})
	public Result cleanCache(@NotNull @PathVariable(required = true) String type){
		Result result = new Result();
			switch (type) {
				case "token":
					cacheService.cleanCacheAllToken();
					break;
				case "permiss":
					cacheService.cleanCacheAllRolePermiss();
					break;
				default:
					result.setMsg("没有此类型");
					result.setCode(1);
					break;
			}
		return result;
	}
	
	
	
}